﻿Imports Microsoft.VisualBasic
Imports System.Security.Cryptography

Public Class Encrypt
    Public Shared Function Encrypt(ByVal sEncrypt As String, ByVal sKey As String) As String
        Try
            Dim arrKey() As Byte
            Dim arrEncrypt() As Byte = UTF8Encoding.UTF8.GetBytes(sEncrypt)
            Dim obj_Md5_Service As MD5CryptoServiceProvider = New MD5CryptoServiceProvider()
            arrKey = obj_Md5_Service.ComputeHash(UTF8Encoding.UTF8.GetBytes(sKey))
            Dim TdCP As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvider()
            TdCP.Key = arrKey
            TdCP.Mode = CipherMode.ECB
            TdCP.Padding = PaddingMode.PKCS7
            Dim cTransform As ICryptoTransform = TdCP.CreateEncryptor()
            Dim arrResult() As Byte = cTransform.TransformFinalBlock(arrEncrypt, 0, arrEncrypt.Length)
            Return Convert.ToBase64String(arrResult, 0, arrResult.Length)
        Catch ex As System.Security.Cryptography.CryptographicException
            Throw (New System.Exception(ex.Message, ex.InnerException))
        End Try
    End Function
End Class
